define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function() {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/tranmoney/index' + location.search, 
                    table: 'tranmoney',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id') },
                        {
                            field: 'pay_uid',
                            title: __('Pay_uid'),
                            formatter: function(value, row, index) {
                                if (value == 0) {
                                    return "<span style='color:green'> 系统  </span>";
                                } else {
                                    return row['pay_name'];
                                }
                            }
                        },
                        {
                            field: 'get_uid',
                            title: __('Get_uid'),
                            formatter: function(value, row, index) {
                                if (value == 0) {
                                    return "<span style='color:green'> 系统  </span>";
                                } else {
                                    return row['get_name'];
                                }
                            }
                        },
                        {
                            field: 'get_type',
                            title: __('Get_type'),
                            formatter: Table.api.formatter.status,
                            searchList: {
                                '1': __('减少余额'),
                                '2': __('增加余额'),
                                '3': __('减少积分'),
                                '4': __('增加积分'),
                                '5': __('余额支付费用'),
                                '6': __('余额购买商品'),
                                '7': __('积分支付费用'),
                                '8': __('积分购买商品'),
                                '9': __('扣除余额'),
                                '10': __('支出费用'),
                                '11': __('扣除余额1'),
                                '12': __('支出费用2'),
                            },
                        },
                        {
                            field: 'get_num',
                            title: __('Get_num'),
                            formatter: function(value, row, index) {
                                if (value > 0) {
                                    return "<span style='color:green'>" + value + "</span>";
                                } else {
                                    return "<span style='color:red'>" + value + "</span>";
                                }
                            }
                        },
                        { field: 'get_now_num', title: __('Get_now_num'), operate: 'BETWEEN' },
                        { field: 'create_time', title: __('create_time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true },
                        // { field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function() {
            Controller.api.bindevent();
        },
        edit: function() {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function() {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});